#include <cstdio>
#include <algorithm>
typedef long long ll;
int t;
int n;
ll a,b;
ll sum;
int main(void){
    scanf("%d",&t);
    while(t--){
        sum=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%lld%lld",&a,&b);
            sum+=(a*b);
        }
        printf("%lld\n",sum);
    }
    return 0;
}